package hang.com.mvptest.login.presenter;

import android.os.Handler;
import android.os.Looper;


import java.util.logging.LogRecord;

import hang.com.mvptest.login.model.IUser;
import hang.com.mvptest.login.model.UserModel;
import hang.com.mvptest.login.view.ILoginView;

/**
 * Created by hang on 2017/2/22.
 */

public class LoginPresenterCompl extends ILoginPresenter {

    ILoginView iLoginView;
    IUser user;
    Handler handler;

    public LoginPresenterCompl(ILoginView iLoginView){
        this.iLoginView = iLoginView;
        initUser();
        handler = new Handler(Looper.getMainLooper());
    }

    private void initUser(){
        user = new UserModel("mvp","mvp");
    }

    @Override
    public void clean() {
        iLoginView.onCleanText();
    }

    @Override
    public void doLogin(String name, String password) {
        final int code = user.checkUserValidity(name,password);
        final Boolean result = code == 0;
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                iLoginView.onLoginResult(result,code);
            }
        },3000);

    }

    @Override
    public void setProgressBarVisibility(int visibility) {
        iLoginView.onSetProgressBarVisibility(visibility);
    }
}
